<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul,
        li {
            list-style: none;
        }

        li {
            width: 200px;
            height: 100px;
            background: blueviolet;
            margin: 10px;
            font-size: 30px;
        }

        #box {
            width: 500px;
            height: 500px;
            border: 3px dotted pink;
            margin-left: 300px;
        }
    </style>
</head>

<body>
    <!--  draggable="true" 允许拖拽 -->
    <ul>
        <li draggable="true">1</li>
        <li draggable="true">2</li>
        <li draggable="true">3</li>
    </ul>

    <div id="box"></div>
    <script>
        //1.获取元素信息
        var oUl = document.getElementsByTagName('ul')[0];
        var aLi = oUl.getElementsByTagName('li');
        var oBox = document.getElementById('box');
        //2.开始拖拽
        for (var i = 0; i < aLi.length; i++) {
            aLi[i].index = i;
            aLi[i].ondragstart = function (ev) {
                console.log("开始拖拽");
                //传参
                ev.dataTransfer.setData("index", this.index);
            }
        }

        //3.到目的地
        oBox.ondragover = function (ev) {
            //阻止默认事件
            ev.preventDefault();
        }
        //在目的地上方放开鼠标
        oBox.ondrop = function (ev) {
            //获取传过来的参数
            var index = ev.dataTransfer.getData("index");
            //删除li。放到 div中
            oBox.appendChild(aLi[index]);

        }

//bug:按照123的顺序拖动元素时，出问题了，需要修改
    </script>
</body>

</html>